# Helpers for numpy

import numpy as np


# numpy

def memloc(arr):
    """Get the memory block address of an array"""
    return arr.__array_interface__['data'][0]

def get_data_base(arr):
    """For a given `numpy.ndarray` instance, finds
    the base array that "owns" the actual data."""
    base = arr
    while isinstance(base.base, np.ndarray):
        base = base.base
    return base

def arrays_share_data(x, y):
    """x, y - `numpy.ndarray` instances"""
    return get_data_base(x) is get_data_base(y)

# ravel only returns a copy if needed, but flatten always
